# build stage
FROM node:18.20.4 as build-stage
WORKDIR /app
# RUN npm install -g pnpm
COPY package.json ./
# use datastory registry
# RUN npm config set registry http://npm.registry.datastory.com.cn
RUN npm config set registry https://registry.npmmirror.com
RUN npm install
COPY . .
ENV NODE_OPTIONS --max-old-space-size=10240
ARG STAGE
ENV STAGE $STAGE
RUN npm run $STAGE

# production stage
FROM nginx:stable-alpine as production-stage

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV TZ Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY --from=build-stage /app/default.conf /etc/nginx/conf.d/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
